var http = require('http');
http.createServer(function (request, response) {
    // 如果你想给浏览器响应一个html页面, 设置response.writeHead(200, { 'Content-Type': 'text/html;charset=utf-8' });
    // 如果你想给浏览器响应一个JSON数据, 设置response.writeHead(200, { 'Content-Type': 'application/json' });
    response.writeHead(200, { 'Content-Type': 'application/json' });
    const str = `<!DOCTYPE html>
                    <html lang="en">
                    <head>
                        <meta charset="UTF-8">
                        <meta http-equiv="X-UA-Compatible" content="IE=edge">
                        <meta name="viewport" content="width=device-width, initial-scale=1.0">
                        <title>Document</title>
                        <style>
                            div {
                                width: 100px;
                                height: 100px;
                                background-color: red;
                            }
                        </style>
                    </head>
                    <body>
                        <div></div>
                    </body>
                    </html>`
    // 当做接口服务器,响应一个数据
    const obj = [
        {
            id: 1,
            name: '张三',
            age: 20
        },
        {
            id: 2,
            name: '李四',
            age: 30
        }
    ]
    response.end(JSON.stringify(obj));
}).listen(8081);

console.log('Server running at http://127.0.0.1:8081/');